﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using SpringStudio.Common;
using SpringStudio.DAL;
using Sdepci.InfoCode.BLL.CodeDesign;

namespace Sdepci.InfoCode.Web.CodeDesign
{
    public partial class GetSerial : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.IsPostBack)
            {
                this.Response.Clear();
                this.Response.Write(GetNumber());
                this.Response.End();
            }
        }

        private string GetNumber()
        {
            // 检查参数完整性
            if (this.Request.QueryString["RuleGuid"] == null || this.Request.QueryString["RuleGuid"].Trim() == "")
            {
                return "error";
            }

            if (this.Request.QueryString["SerialReference"] == null || this.Request.QueryString["SerialReference"].Trim() == "")
            {
                return "error";
            }

            if (this.Request.QueryString["SerialLength"] == null || this.Request.QueryString["SerialLength"].Trim() == "")
            {
                return "error";
            }

            if (this.Request.QueryString["SerialStart"] == null)
            {
                return "error";
            }

            // 返回流水号
            string serial = new BriefManager().CreateSerialNumber(this.Request.QueryString["RuleGuid"].Trim(),
                this.Request.QueryString["SerialReference"].Trim(), this.Request.QueryString["SerialLength"].Trim(), this.Request.QueryString["SerialStart"].Trim());
            if (serial != null)
            {
                return serial;
            }
            else
            {
                return "error";
            }
        }
    }
}
